<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="订单编号" prop="orderNo">
          <el-input
            v-model="queryParams.orderNo"
            placeholder="请输入订单编号"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="创建时间" style="width: 308px">
          <el-date-picker
            v-model="dateRange"
            value-format="YYYY-MM-DD"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
  
      <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
        <el-table-column label="序号" type="index" align="center" prop="id" width="80"/>
        <el-table-column label="订单编号" align="center" prop="orderNo" show-overflow-tooltip="" />
        <el-table-column label="商品名称" align="center" prop="skuName" />
        <el-table-column label="订单状态" align="center" prop="status">
          <template #default="scope">
            <dict-tag :options="order_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="订单金额" align="center" prop="amount" >
        <template #default="scope">
          <el-tag>{{ scope.row.amount/100 }}元</el-tag>
        </template>
        </el-table-column>
        <el-table-column label="订单时间" align="center" prop="createTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button link type="primary"  @click="handleUpdate(scope.row)" v-hasPermi="['manage:order:edit']">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
  
      <!-- 查看详情对话框 -->
      <el-dialog :title="title" v-model="open" width="500px" append-to-body>
        <el-form ref="orderRef" :model="form" :rules="rules" label-width="80px">
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </template>
      </el-dialog>
    </div>
  </template>
  
  <script setup name="Order">
  import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/manage/order";
  
  const { proxy } = getCurrentInstance();
  const { order_status } = proxy.useDict('order_status');
  
  const orderList = ref([]);
  const open = ref(false);
  const loading = ref(true);
  const showSearch = ref(true);
  const ids = ref([]);
  const single = ref(true);
  const multiple = ref(true);
  const total = ref(0);
  const title = ref("");
  const dateRange = ref([]);
  
  const data = reactive({
    form: {},
    queryParams: {
      pageNum: 1,
      pageSize: 10,
      orderNo: null,
      createTime: null,
    },
    rules: {
    }
  });
  
  const { queryParams, form, rules } = toRefs(data);
  
  
  
  
  /** 查询订单列表 */
  function getList() {
    loading.value = true;
    listOrder(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
      orderList.value = response.rows;
      total.value = response.total;
      loading.value = false;
    });
  }
  
  // 取消按钮
  function cancel() {
    open.value = false;
    reset();
  }
  
  
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
  }
  
  /** 重置按钮操作 */
  function resetQuery() {
    dateRange.value = [];
    proxy.resetForm("queryRef");
    handleQuery();
  }
  
  
  /** 查看详情操作 */
  function handleUpdate(row) {
    const _id = row.id || ids.value
    getOrder(_id).then(response => {
      form.value = response.data;
      open.value = true;
      title.value = "订单详情";
    });
  }
  
  
  getList();
  </script>
  